# Makefile for compilation of OpenModelica Cpp runtime

# specify a list of target platforms, including dynamic, static
# and platform triples for cross compilation
PLATFORMS=static dynamic

OMBUILDDIR=
LIBINSTALLEXT=
LIB_OMC=

-include Makefile.env

BOOST_ROOT_COMMAND="@BOOST_ROOT_COMMAND@"
BOOST_STATIC_LINKING_COMMAND="@BOOST_STATIC_LINKING_COMMAND@"
BOOST_REALPATHS_COMMAND="@BOOST_REALPATHS_COMMAND@"
RUNTIME_PROFILING_COMMAND="@RUNTIME_PROFILING_COMMAND@"
SCOREP_COMMAND="@SCOREP_COMMAND@"
SCOREP_HOME="@SCOREP_HOME@"
FMU_SUNDIALS_COMMAND="@FMU_SUNDIALS_COMMAND@"
LOGGER_COMMAND="@LOGGER_COMMAND@"
CPP_03_COMMAND="@CPP_03_COMMAND@"

#Experimental
PARALLEL_OUTPUT_COMMAND="@PARALLEL_OUTPUT_COMMAND@"

#use this call to use precompiled headers
#BUILDTYPE = Release
#use this call if you want to debug the cpp runtime
BUILDTYPE=@CMAKE_BUILDTYPE@

CMAKE_COMMANDS=@CMAKE_COMMANDS@
CMAKE_ARGS=$(patsubst CMAKE_%, -D%, $(filter CMAKE_%, $(MAKEFLAGS)))

CMAKE_FLAGS=-DCMAKE_BUILD_TYPE=$(BUILDTYPE) $(BOOST_ROOT_COMMAND) $(BOOST_STATIC_LINKING_COMMAND) $(CPP_03_COMMAND) $(BOOST_REALPATHS_COMMAND) $(PARALLEL_OUTPUT_COMMAND) $(RUNTIME_PROFILING_COMMAND) $(SCOREP_COMMAND) $(FMU_SUNDIALS_COMMAND) $(LOGGER_COMMAND) -DCMAKE_INSTALL_PREFIX:PATH="$(OMBUILDDIR)" -DLIBINSTALLEXT=$(LIBINSTALLEXT) -DLIB_OMC=$(LIB_OMC) -DSCOREP_HOME:STRING="$(SCOREP_HOME)" $(BUILD_DOC_COMMAND) $(CMAKE_ARGS) -DOpenMP_CXX_FLAGS="$(OMPCFLAGS)"

runtimeCpp: omcCAPIinstall
	$(foreach PLATFORM, $(PLATFORMS), \
	  mkdir -p Build_$(PLATFORM); \
	  (cd ./Build_$(PLATFORM) && echo "change to Build_$(PLATFORM)" && $(CMAKE_COMMANDS) cmake -DPLATFORM=$(PLATFORM) $(CMAKE_FLAGS) ../); \
	  $(MAKE) -C Build_$(PLATFORM) VERBOSE=1;)

install: runtimeCpp
	$(foreach PLATFORM, $(PLATFORMS), \
	  (cd Build_$(PLATFORM); $(MAKE) install);)

omcCAPIinstall:
	mkdir -p Build_CAPI;
	(test  `uname` = Darwin || (cd ./Build_CAPI; echo "change to Build_CAPI"; \
	  mkdir -p tmp; \
	  $(CMAKE_COMMANDS) cmake -DPLATFORM=$(PLATFORM) -DOMC_PATH="$(OMBUILDDIR)" -DOMCAPI_ROOT="../../Build_CAPI/tmp" $(CMAKE_FLAGS) ../omcWrapper/ -DCMAKE_INSTALL_PREFIX:PATH="./tmp"; \
	  $(MAKE) install;))


clean:
	$(foreach PLATFORM, $(PLATFORMS), \
	  rm -R -f Build_$(PLATFORM);)

Makefile: Makefile.in
	cd @top_builddir@ && ./config.status
